import axios from "axios";
import config from "../config";

//初始化axios
axios.defaults.baseURL = config.config.apiUrlPrefix;

function addToken(url) {
    let back = url;
    let _token = localStorage.getItem("local:_token");

    if (url.indexOf("?") != -1) {
        back = url + "&_token=" + _token;
    } else {
        back = url + "?_token=" + _token;
    }

    return back;
}

function post(url, param = {}) {
    url = addToken(url);
    return axios.post(url, param);
}

function get(url, param = {}) {
    url = addToken(url);
    return axios({
        method: "get",
        url: url,
        params: param,
        responseType: "json"
    })
}

export { addToken, get, post };

